package com.sl.au.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.sl.au.entity.SalemanMobilize;
import com.sl.au.service.SalemanMobilizeService;

/**
 * 片区人员调动管理控制器
 * @author HXZ
 *
 */
@RestController
@RequestMapping(value = "/ui/salemanMobilize")
public class SalemanMobilizeController extends BaseController {

	@Autowired
	SalemanMobilizeService salemanMobilizeService;

	/**
	 * 页面显示
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView index() {
		ModelAndView modelAndView = this.createLayoutView("salemanMobilize/salemanMobilizeindex");

		return modelAndView;
	}

	/**
	 * 获取页面数据
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "getpage", method = RequestMethod.GET)
	public Map<String, Object> getPage(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		int start = Integer.parseInt(request.getParameter("start"));
		int length = Integer.parseInt(request.getParameter("length"));
		String key = request.getParameter("key");
		String findKey='%'+key+'%';
		List<SalemanMobilize> salemanMobilizes = null;
		Long count = null;
		//判断是否有查询字段
		if (StringUtils.hasText(key)) {
			salemanMobilizes = salemanMobilizeService.getSalemanMobilizes(start, length, findKey, null, null);
			count = (long) salemanMobilizes.size();
		} else {
			salemanMobilizes = salemanMobilizeService.getPage(start, length, null, null, null);
			count = salemanMobilizeService.getRepository().count();
		}
		map.put("data", salemanMobilizes);
		map.put("draw", request.getParameter("draw"));
		map.put("recordsFiltered", count);
		map.put("recordsTotal", count);
		return map;
	}

}
